<template>
  <view>
    <button type="primary" plain open-type="getUserInfo" @getuserinfo="handleGetUserInfo">
      获取授权
    </button>

  </view>
</template>

<script>
import request from "../../utils/request.js";
import { login } from "../../utils/asyncWX";
export default {
  data() {
    return {};
  },
  methods: {
    async handleGetUserInfo(e) {
      try {
        console.log(e);
        const { encryptedData, rawData, iv, signature } = e.detail;
        // 获取code值
        const { code } = await login();
        // const loginParams = { encryptedData, rawData, iv, signature, code };
        // 发请求
        // const res = await request("/users/wxlogin", loginParams, "post");
        
        let token =
          "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo";
        uni.setStorageSync("token", token);
        uni.navigateBack({
          delta: 1,
        });
      } catch (err) {
        console.log(err);
      }
    },
  },
};
</script>

<style lang="less">
button {
  margin-top: 40rpx;
  width: 70%;
}
</style>
